package de.damontools.awolowa.application;

import java.util.ArrayList;

import de.damontools.awolowa.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class LogAdapter extends ArrayAdapter<Log> {
	private ArrayList<Log> items;
	private Context context;

	/**
	 * Constructor
	 * 
	 * @param context
	 * @param textViewResourceId
	 * @param items
	 */
	public LogAdapter(Context context, int textViewResourceId,
			ArrayList<Log> items) {
		super(context, textViewResourceId, items);
		this.context = context;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.activity_log, null);
		}
		Log o = items.get(position);
		
		if (o != null) {
			TextView tt = (TextView) v.findViewById(R.id.log_head);
			TextView bt = (TextView) v.findViewById(R.id.log_body);
			if (tt != null) {
				tt.setText(Integer.toString(o.getId()));
			}
			if (bt != null) {
				bt.setText(Integer.toString(o.getProfil()));
			}
		}
		return v;
	}
}
